<template>
  <div class="goodsListData">
    <router-link class="item1" v-for="item in goodsList" :key="item.id" :to="'/tabbar/goodInfo/' + item.id">
      <img :src="item.img_url">
      <p class="goodsTitle">{{item.title}}</p>
      <div class="goodsContent">
        <div class="goodsPrice">
          <span class="new">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </div>
        <div class="goodsSell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </div>
      </div>
    </router-link>
    <mt-button size="large" type="danger" @click="getmore">加载更过</mt-button>
  </div>
  
</template>

<script>
import {Toast} from "mint-ui"
export default {
    data(){
        return{
            // 第几页 的数据
            pageindex:1,
            goodsList:[],      //用于   存储 发送请求 获得的数据
        }
    },
    created() {
        this.getGoodsList()
    },
    methods: {
        getGoodsList(){
            this.$http.get("api/getgoods?pageindex=" + this.pageindex).then(result=>{
                if(result.body.status===0){
                    // if(this.goodsList.length == result.body.message.length){
                    //     Toast("我也是有底线的")
                    // } 
                     this.goodsList = this.goodsList.concat(result.body.message)

                } 
                if(result.body.message.length  == 0){
                    Toast("没有更多商品了哦！！！！")
                }
            })
        },
        getmore(){
            this.pageindex++
            this.getGoodsList()
        }
    },
};
</script>

<style lang="less" scoped>
.goodsListData {
    display: flex;
    flex-wrap: wrap;
    padding: 5px;
    justify-content: space-between;
  .item1 {
      width: 49%;
      border: 1px solid #ccc;
      margin: 0 0 4px 0;
      padding: 3px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
        img {
            width: 100%;
        }
        .goodsTitle {
            font-size: 16px;
            color: black;
            font-weight: bold;
        }
        .goodsContent{
            background-color: #eee;
            padding: 3px;
            .goodsPrice{
                margin-bottom: 5px;
                .new{
                    color: red;
                    font-size: 16px;
                }
                .old{
                    color: #aaa;
                    font-size: 13px;
                    margin-left: 5px;
                    text-decoration: line-through;
                }
            }
            .goodsSell{
                color: #aaa;
                font-size: 13px;
                display: flex;
                justify-content: space-between;
            }
        }
  }
}
</style>
